package com.codeduck.kafka.producer;

import org.apache.kafka.clients.producer.ProducerConfig;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;


/**
 * @author: <a href="mailto:codeduck@163.com">Codeduck</a>
 * @date: 2023/6/23
 */
public enum ProducerProperties {
    INSTANCE;
    private static final String DEFAULT_CLIENT_ID = "CID_PRODUCER_";
    private Properties props = new Properties();

    ProducerProperties() {
        InputStream inputStream = ProducerProperties.class.getClassLoader().getResourceAsStream("kafka/producer.properties");
        try {
            props.load(inputStream);
            props.putIfAbsent(ProducerConfig.CLIENT_ID_CONFIG,  DEFAULT_CLIENT_ID);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static Properties getProperties() {
        return ProducerProperties.INSTANCE.props;
    }

}

